#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: update_01_20210508.py
# @time: 2021/5/8 10:08
# @desc:
from .utils.mongo_tools import retrieve_all_mongo_values, update_mongo_value
from .views.configs import SCENE_COLLECTION, STANDARD_CLAMP_COLLECTION

scene = retrieve_all_mongo_values(
    {},
    collection_name=SCENE_COLLECTION,
)

standard_clamp = retrieve_all_mongo_values(
    {},
    collection_name=STANDARD_CLAMP_COLLECTION,
)

standard_clamp_number_list = [i["number"] for i in standard_clamp]

for i in scene:

    if "standardClamp" in i.keys():
        if i["standardClamp"] is None:
            i["standardClamp"] = []
        elif len(i["standardClamp"]) > 0:
            if i["standardClamp"][0] in standard_clamp_number_list:
                continue
            elif i["standardClamp"][0] not in standard_clamp_number_list:
                print(i["standardClamp"])
                i["standardClamp"] = []
        else:
            i["standardClamp"] = []
    else:
        i["standardClamp"] = []
    update_mongo_value(
        filter_condition={"number": i["number"]},
        new_value={"$set": i},
        collection_name=SCENE_COLLECTION,
    )
